#!/bin/sh
#jerry.du 2009-01-05, show stat information in linux /proc/$pid/stat

if [ $# -lt 1 ]; then
	echo "Usage: show_stat pid"
	echo "    show_stat 100"
	exit 1
fi

var_stat=
var_pid=$1

if [ -d /proc/$var_pid ]; then
	var_stat=`cat /proc/$var_pid/stat`
else
	echo "process $var_pid is not exist"
	exit 1
fi

#cause es3628bt's busybox can't support echo -e currently, we use space instead
echo "process $var_pid stat information:"
echo -en "pid:                   "
echo $var_stat | cut -d" " -f1
echo -en "tcomm:                 "
echo $var_stat | cut -d" " -f2
echo -en "state:                 "
echo $var_stat | cut -d" " -f3
echo -en "ppid:                  "
echo $var_stat | cut -d" " -f4
echo -en "pgid:                  "
echo $var_stat | cut -d" " -f5
echo -en "sid:                   "
echo $var_stat | cut -d" " -f6
echo -en "tty_nr:                "
echo $var_stat | cut -d" " -f7
echo -en "tty_pgrp:              "
echo $var_stat | cut -d" " -f8
echo -en "task->flags:           "
echo $var_stat | cut -d" " -f9
echo -en "min_flt:               "
echo $var_stat | cut -d" " -f10
echo -en "cmin_flt:              "
echo $var_stat | cut -d" " -f11
echo -en "maj_flt:               "
echo $var_stat | cut -d" " -f12
echo -en "cmaj_flt:              "
echo $var_stat | cut -d" " -f13
echo -en "utime:                 "
echo $var_stat | cut -d" " -f14
echo -en "stime:                 "
echo $var_stat | cut -d" " -f15
echo -en "cutime:                "
echo $var_stat | cut -d" " -f16
echo -en "cstime:                "
echo $var_stat | cut -d" " -f17
echo -en "priority:              "
echo $var_stat | cut -d" " -f18
echo -en "nice:                  "
echo $var_stat | cut -d" " -f19
echo -en "num_threads:           "
echo $var_stat | cut -d" " -f20
echo -en "start_time:            "
#the do_task_stat in /proc/array.c printf a char '0' between the string
echo $var_stat | cut -d" " -f22
echo -en "vsize:                 "
echo $var_stat | cut -d" " -f23
echo -en "mm_rss:                "
echo $var_stat | cut -d" " -f24
echo -en "rsslim:                "
echo $var_stat | cut -d" " -f25
echo -en "mm->start_code:        "
echo $var_stat | cut -d" " -f26
echo -en "mm->end_code:          "
echo $var_stat | cut -d" " -f27
echo -en "mm->start_stack:       "
echo $var_stat | cut -d" " -f28
echo -en "esp:                   "
echo $var_stat | cut -d" " -f29
echo -en "eip:                   "
echo $var_stat | cut -d" " -f30
echo -en "pending signal:        "
echo $var_stat | cut -d" " -f31
echo -en "blocked signal:        "
echo $var_stat | cut -d" " -f32
echo -en "ignore signal:         "
echo $var_stat | cut -d" " -f33
echo -en "catch signal:          "
echo $var_stat | cut -d" " -f34
echo -en "wchan:                 "
echo $var_stat | cut -d" " -f35
echo -en "swapped page(unused):  "
echo $var_stat | cut -d" " -f36
echo -en "swapped total(unused): "
echo $var_stat | cut -d" " -f37
echo -en "exit_signal:           "
echo $var_stat | cut -d" " -f38
echo -en "task_cpu:              "
echo $var_stat | cut -d" " -f39
echo -en "rt_priority:           "
echo $var_stat | cut -d" " -f40
echo -en "policy:                "
echo $var_stat | cut -d" " -f41
echo -en "delayacct_blkio_ticks: "
echo $var_stat | cut -d" " -f42

